﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace weiqijiance.外廓尺寸
{
    public class wkccxincheng : wkccbass
    {
        public wkccxincheng(string sip)
        {
            init(sip);
        }
        public static LWH25BUtil.lwh25butil lwh25butilcontrol;

        public bool init(string sip)
        {
            try
            {
                //连接服务器
                string eisid = "";
                lwh25butilcontrol = new LWH25BUtil.lwh25butil();
                lwh25butilcontrol.initSocket(sip, "5464");
                LWH25BUtil.lwh25butil.saveLogInf("服务器IP:" + sip + " Port:" + "5464" + "开始连接");
                string message = lwh25butilcontrol.init_equipment(out eisid);
                LWH25BUtil.lwh25butil.saveLogInf(message);
                if (message == "连接成功")
                {
                    //    labelESDID.Text = eisid;
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("创建外廓尺寸连接失败:" + message);
                }
                //创建环境

                string result = "";
                string info = "";

                lwh25butilcontrol.createBackground(out result, out info);
                if (result != "1")
                {
                    System.Windows.Forms.MessageBox.Show("创建外廓尺寸背景失败:" + "result:" + result + " info:" + info);
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("外廓尺寸初始化失败：" + ex.Message);
            }
            return true;
        }

        public override bool getliucheng_artificial(string lengthxz, string widthxz, string heightxz, ref int length, ref int width, ref int height, ref int length_artificial, ref int width_artificial, ref int height_artificial, ref int artificial)
        {
            int lbgd;
            int.TryParse(flowbass.lbgd, out lbgd);

            string result = "", info = "";
            if (lwh25butilcontrol.loginVehicle(flowbass.jylsh, flowbass.sPlate, flowbass.sxcrh.Contains("注册") ? "1" :flowbass.sxcrh.Contains("过户")?"1": "0",
objwkcc.m_mainform.objbass.objdb.getsqlmessage("table_hpzl", flowbass.sPclass),
flowbass.svin,
objwkcc.m_mainform.objbass.objdb.getsqlmessage("table_cllx", flowbass.sCllx),
flowbass.owner,
"",
true,
lbgd > 1 ? true : false,
flowbass.sxcrh.Contains("注册") ? true : false,
false,
flowbass.ichang.ToString(),
flowbass.ikuan.ToString(),
flowbass.igao.ToString(),
lbgd,
flowbass.ihxc,
flowbass.ihxk,
flowbass.ihxg,
flowbass.szhouju + "////",
flowbass.iCLZBZL,
flowbass.iCLZZL, out result, out info))
            {
                objwkcc.sneirongWKCC = "发送车辆信息结果：result:" + result + " info:" + info;
                objwkcc.WKCCshow();

            }
            else
            {
                objwkcc.sneirongWKCC = "车辆信息发送失败";
                objwkcc.WKCCshow();
                return false;
            }

            if (lwh25butilcontrol.StartTest(flowbass.jylsh, out result, out info))
            {
                objwkcc.sneirongWKCC = "开始测量发送结果：result:" + result + " info:" + info;
                objwkcc.WKCCshow();
            }
            else
            {
                objwkcc.sneirongWKCC = "开始测量发送失败";
                objwkcc.WKCCshow();
                return false;
            }

            //测量状态
            for (; ; )
            {
                if (lwh25butilcontrol.ReadTestStatus(flowbass.jylsh, out result, out info))
                {
                    objwkcc.sneirongWKCC = "测量状态发送结果：result:" + result + " info:" + info;
                    objwkcc.WKCCshow();
                    if (result == "1")
                        break;
                }
                else
                {
                    objwkcc.sneirongWKCC = "测量状态发送失败";
                    objwkcc.WKCCshow();
                }
                if (!objwkcc.bwkcc)
                {
                    if (lwh25butilcontrol.AbandonVehicle(flowbass.jylsh, out result, out info))
                    {
                        objwkcc.sneirongWKCC = "放弃测量结果：result:" + result + " info:" + info;
                        objwkcc.WKCCshow();
                    }
                    else
                    {
                        objwkcc.sneirongWKCC = "放弃测量发送失败";
                        objwkcc.WKCCshow();
                    }
                    return false;
                }
                System.Threading.Thread.Sleep(1000);
            }

            int length2 = 0;
            int width2 = 0;
            int height2 = 0;
            int leftheaderHeight = 0;
            int rightheaderHeight = 0;
            int vanHeight = 0;
            int vanlength = 0;
            int vanWidhth = 0;
            string wheelDistance = "";
            int kerbMass = 0;
            string lengthJudge = "";
            string heightJudge = "";
            string widthJudge = "";
            string headerJudge = "";
            string kerbMassJudge = "";
            string wheelDistanceJudge = "";
            string testtime = "";
            string totalJudge = "";

            if (!lwh25butilcontrol.readTestResult(flowbass.jylsh, out result, out info, out length2, out width2, out height2, out leftheaderHeight,
                out rightheaderHeight, out wheelDistance, out vanlength, out vanWidhth, out vanHeight, out kerbMass,
                out lengthJudge, out widthJudge, out heightJudge, out headerJudge, out wheelDistanceJudge, out kerbMassJudge,
                out totalJudge, out testtime))
            {
                objwkcc.sneirongWKCC = "读取数据发送失败";
                objwkcc.WKCCshow();
            }

            length = length2;
            width = width2;
            height = height2;

            return true;
        }


    }
}
